@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
            需求列表
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Demand</a></li>
            <li class="active">Demand List</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">内容</h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>权重</th>
                                <th>创建时间</th>
                                <th>名称</th>
                                <th>线索名</th>
                                <th>产品类型</th>
                                <th>报价</th>
                                <th>描述</th>
                                <th>附件</th>
                                <th>状态</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($demand as $d)
                                <tr>
                                    <td>{{ $d['id'] }}</td>
                                    <td>{{ $d['rank'] }}</td>
                                    <td>{{ $d['create_time'] }}</td>
                                    <td>{{ $d['name'] }}</td>
                                    <td>{{ App\Model\Clue::find($d['clue_id'])['name'] }}</td>
                                    <td>{{ App\Model\Product::find($d['product_id'])['name'] }}</td>
                                    <td>{{ $d['price'] }}</td>
                                    <td>{{ $d['description'] }}</td>
                                    <td>附件</td>
                                    <td>
                                        @if($d['status'] == 1)
                                            <a class="btn btn-danger btn-xs" href="javascript:demandStatus('{{ $d['id'] }}',0)">禁用<a>
                                        @elseif($d['status'] == 0)
                                            <a class="btn btn-success btn-xs" href="javascript:demandStatus('{{ $d['id'] }}',1)">启用<a>
                                        @endif
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
@stop
@section('script')
    <script>
        //禁用,启用
        function demandStatus(id,status) {
            $.ajax({
                url: '/demand/demandStatus',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        window.location.href=window.location.href;
                        layer.msg(res.msg, {time:1500, icon:6})
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5});
                    }
                }
            });
        }
    </script>
@stop